js.underas.controller.Controller = new Class({
	"uid":0
	,"_html":null
	,"initialize":function(tagh,tagc){
		this.uid = js.underas.core.Underas.getUid();
		this._html = new Element(tagh);
		//this._html = Elements.from(tagp);
		this.getEle().addClass("Controller").set("html",tagc).set("id","uid_"+this.uid);
		this.setBlankWhenNull(true);
	}
	,"addEvent":function(p_on,p_event_fn,p_bind){
		if(p_bind){
			this.getEle().addEvent(p_on,p_event_fn.bind(p_bind));
		}else{
			this.getEle().addEvent(p_on,p_event_fn);
		}
		return this.getEle();
	}
	,"getEle":function(p_sel){
		if(!p_sel){
			return this._html;
		};		
		return this._html.getElement(p_sel);
	}
	,"getInput":function(){
		//return $$("#_uid"+this.uid); //ideial
		return this.getEle(".inputtt");
	}
	,"setLabel":function(nlabel){	
		this.getEle("label").set("text",nlabel);
	}
	,"setValue":function(vl){		
		var palavra = new String(vl);//.toUpperCase();		
		this.getInput().set("value",palavra);//.change();
	}
	,"setTransient":function(on){		
		var readyS = (on)?"y":"n";		
		this.getEle().set("data-transient",readyS);//.change();
	}
	,"isTransient":function(){
		return this.getEle().get("data-transient")=="y";
	}
	,"setBlankWhenNull":function(on){		
		var whennull = (on)?"y":"n";		
		this.getEle().set("data-blankwhennull",whennull);//.change();
	}
	,"isBlankWhenNull":function(){
		return !this.getEle().get("data-blankwhennull")=="n";
	}
	,"setFixed":function(on){		
		var readyS = (on)?"y":"n";		
		this.getEle().set("data-fixed",readyS);//.change();
	}
	,"isFixed":function(){
		return this.getEle().get("data-fixed")=="y";
	}
	,"getValue":function(){
		return this.getInput().get("value").trim();
	}
	,"setEnable":function(on,p_posi){
		if(on){
			if(!p_posi){				
				this.getEle(".input-group").getChildren(".cposis").set("data-enable","y");
				this.getEle(".input-group").getChildren(".cposis").set("disabled",!on).removeClass("Disabled").setStyle("opacity",1);
			}else{
				this.getEle(".cposi_"+p_posi).set("data-enable","y");
				this.getEle(".cposi_"+p_posi).set("disabled",!on).removeClass("Disabled").setStyle("opacity",1);
			}
		}else{
			if(!p_posi){
				this.getEle(".input-group").getChildren(".cposis").set("data-enable","n");
				this.getEle(".input-group").getChildren(".cposis").set("disabled",!on).addClass("Disabled").setStyle("opacity",0.6);
			}else{
				this.getEle(".cposi_"+p_posi).set("data-enable","n");
				this.getEle(".cposi_"+p_posi).set("disabled",!on).addClass("Disabled").setStyle("opacity",0.6);
			}
		}
	}
	,"isEnable":function(p_posi){	
		var enableS = "n";
		if(!p_posi){
			enableS = this.getInput().get("data-enable");
		}else{
			enableS = this.getEle(".cposi_"+p_posi).get("data-enable");
		};
		return enableS!="n";
	}
	,"setSize":function(nsize){
		var classes = this.getEle().get("class");
		var ns = classes.replace(/col\-sm\-(\d{1,2})/,"col-sm-"+nsize);
		ns = ns.replace(/col\-md\-(\d{1,2})/,"col-md-"+nsize);
		this.getEle().erase('class').addClass(ns);
	}
	,"setMaxLength":function(p_lgt){
		this.getInput().set('maxlength',p_lgt);
	}
	,"setMinLength":function(p_lgt,p_msgerro){
		//this.htmlX.find(".inputtt").attr('maxlength',vl);
	}
	,"setValidation":function(p_mask,p_msgerro){
		//this.htmlX.find(".inputtt").attr('maxlength',vl);
	}
	,"setMinLength":function(vl,p_msgerro){
		//this.htmlX.find(".inputtt").attr('maxlength',vl);
	}
	,"setPlaceHolder":function(p_placeholder){
		this.getEle(".inputtt").set("placeholder",p_placeholder);
	}
	,"show":function(pshow){
		if(pshow){			
			this.getEle().setStyle("display","block");
		}else{
			this.getEle().setStyle("display","none");
		}
	}
	,"isPrimaryKey":function(){
		return this.getEle().get("data-snprimarykey")=="S";
	}
	,"isValid":function(){
		//return true;		
		var vl = this.getValue();//this.getValue();
		return vl.length > 0 == true;
		
	}
	,"setValid":function(p_on){
		if(p_on){
		    this.getEle().removeClass("has-error");
		}else{
			this.getEle().addClass("has-error");
		}
	}
	,"setValidation":function(p_regex,p_msg){
		
	}
	,"setColumn":function(p_column){
		var tcolumn = p_column;
		this.getEle().set("data-snprimarykey","N");				
		if(p_column.indexOf("#")==0){
			this.setTransient(true);
			p_column = p_column.replace("#","@");
		}else if(p_column.indexOf("$")==0){
			this.getEle().set("data-snprimarykey","S");
			p_column = p_column.replace("$","@");
		}else if(p_column.indexOf("!")==0){
			this.setFixed(true);
			p_column = p_column.replace("!","@");
		}
		this.getEle().set("data-column",p_column.replace("@",""));
		//this.getEle().set("data-fieldname",tfieldname);
		
	}
	,"getColumn":function(){
		return this.getEle().get("data-column");
	}
	,"setVarModule":function(p_varmod){
		if(p_varmod){
			this.getEle().set("data-varmod",p_varmod);
		}
	}
	,"getVarModule":function(){
		return this.getEle().get("data-varmod");
	}
});

